﻿using System;
using System.Collections;
using System.Configuration;
using System.Data;
using System.Linq;
using System.Web;
using System.Web.Security;
using System.Web.UI;
using System.Web.UI.HtmlControls;
using System.Web.UI.WebControls;
using System.Web.UI.WebControls.WebParts;
using System.Xml.Linq;
using BCGC.BLL.MarketPlace;
using BCGC.BLL.Helper;

public partial class Admin_view_marketplace : AdminBasePage
{
    public int userID = -1;
    private int ID
    {
        get
        {
            if (string.IsNullOrEmpty(HttpContext.Current.Request.QueryString["id"]) == false)
                return Convert.ToInt32(HttpContext.Current.Request.QueryString["id"]);

            return -1;
        }
    }

    protected void Page_Load(object sender, EventArgs e)
    {
        if (!IsPostBack)
        {
            BindData();
        }
    }

    private void BindData()
    {
        if (ID != -1)
        {
            Market market=Market.GetByID(ID);
            if (market != null)
            {
                litItemID.Text = market.ItemID.ToString();
                userID = market.UserID;
                litDate.Text = market.Date.ToShortDateString();
                fckContent.Value =Server.HtmlDecode(market.MarketContent);
                chkShowContactInfo .Checked= market.ShowContactInfo;
                litTitle.Text = market.Title;
                //litUserMode.Text = market.UserMode;
                //litUserName.Text = market.UserName;
                fckAdminComment.Value = Server.HtmlDecode(market.AdminComment);
                chkActive.Checked = market.IsActive;
                //if (string.IsNullOrEmpty(market.UserAvater))
                //{
                //    imgUserAvater.ImageUrl = "~/App_Themes/AdminDefault/image/NoImageAvatar.jpeg";
                //}
                //else
                //{
                //    imgUserAvater.ImageUrl = market.UserAvater;
                //}
            }
        }
    }
    protected void imbSave_Click(object sender, EventArgs e)
    {
        Market market=Market.GetByID(ID);
        if (market != null)
        {
            market.MarketContent =Server.HtmlEncode(fckContent.Value);
            market.AdminComment = Server.HtmlEncode(fckAdminComment.Value);
            market.IsActive = chkActive.Checked;
            market.ShowContactInfo = chkShowContactInfo.Checked;
            if (market.Save())
            {
                uccResponse.SetSuccessMessage("MarketPlace successfuly updated");
            }
            else
            {
                uccResponse.SetFailMessage("Failed to update MarketPlace");
            }
        }
    }
}
